package com.ad.pet.app.login;

import android.app.Activity;

import com.ad.pet.api.ApiService;
import com.ad.pet.app.RxDisposable;
import com.ad.pet.common.data.http.AppSubscriber;
import com.ad.pet.common.structure.mvp.AbsBasePresenter;
import com.ad.pet.models.remote.login.CategroyCountry;

import java.util.List;

import javax.inject.Inject;

/**
 * Created by SEELE on 2018/3/21.
 */

public class ChoseCountryPresenter extends AbsBasePresenter implements ChoseCountryContract.Presenter {

    private ApiService mApiService;
    private ChoseCountryContract.View mView;

    private Activity mActivity;

    private RxDisposable mRxDisposable;

    @Inject
    public ChoseCountryPresenter(ApiService apiService,
                                Activity activity, RxDisposable rxDisposable) {
        mApiService = apiService;
        mActivity = activity;
        mRxDisposable = rxDisposable;
    }

    @Override
    public void onCreate(ChoseCountryContract.View view) {
        mView = view;
    }

    @Override
    public void onDestroy() {
        if (mRxDisposable!=null)
        mRxDisposable.clear();
        if (mActivity != null) mActivity = null;
        mView = null;
    }






    @Override
    public void getCountry(String longitude,String latitude ) {
        mRxDisposable.add(mApiService.getCountrys(longitude,latitude)
                .subscribe(new AppSubscriber <List<CategroyCountry>>(mView) {
                    @Override
                    public void next(List<CategroyCountry> beans) {
                        mView.getCountrySuccess(beans);
                    }
                }));
    }
}
